package com.ukao.pad.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.DrawableRes;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.mcxtzhang.commonadapter.rv.CommonAdapter;
import com.mcxtzhang.commonadapter.rv.ViewHolder;
import com.ukao.pad.R;
import com.ukao.pad.bean.FactoryBatchInBean;
import com.ukao.pad.utils.CheckUtils;
import com.ukao.pad.utils.DateUtils;

import java.util.List;

import butterknife.BindView;

import static com.ukao.pad.R.id.show_name;

/**
 * 入厂时间轴
 */

public class LogisticsAdapter extends CommonAdapter<FactoryBatchInBean> {


    @BindView(R.id.image)
    ImageView image;
    @BindView(R.id.line_normal)
    View lineNormal;
    @BindView(R.id.show_title)
    TextView showTitle;
    @BindView(show_name)
    TextView showName;
    @BindView(R.id.show_time)
    TextView showTime;

    public LogisticsAdapter(Context context, List<FactoryBatchInBean> datas) {
        super(context, datas, R.layout.adapter_logistics_layout);
    }

    @Override
    public void convert(ViewHolder holder, FactoryBatchInBean testBean) {
        ImageView image=holder.getView(R.id.image);
        View lineNormal=holder.getView(R.id.line_normal);
        TextView showTitle=holder.getView(R.id.show_title);
        TextView showName=holder.getView(show_name);
        TextView showTime=holder.getView(R.id.show_time);
        ImageView arrowsImage=holder.getView(R.id.arrows_image);


        int  pos=holder.getLayoutPosition();
        showName.setText(CheckUtils.isEmptyString(testBean.getName()));
        showTitle.setText(CheckUtils.isEmptyString(testBean.getStatusText()));
        showTime.setText(testBean.getTime()==0?"":  DateUtils.formatDataTime(testBean.getTime()));


        if (testBean.isgreed()){
            image.setImageResource(R.drawable.logistics_circle_greed);
            lineNormal.setBackgroundColor(Color.parseColor("#7ed321"));
            switch (pos) {
                case 2:
                    arrowsImage.setVisibility(View.GONE);
                    lineNormal.setVisibility(View.GONE);
                    break;
                case 1:
                    setCenterShowContent(lineNormal, arrowsImage, View.VISIBLE, R.drawable.logistics_arrows_greed);
                    break;
            }

        }else{
            image.setImageResource(R.drawable.logistics_circle_gray);
            lineNormal.setBackgroundColor(Color.parseColor("#4a4a4a"));
            switch (pos) {
                case 1:
                    setCenterShowContent(lineNormal, arrowsImage, View.VISIBLE, R.drawable.logistics_arrows_gray);
                    break;
                case 2:
                    setEndShowContent(lineNormal, arrowsImage,R.drawable.logistics_arrows_gray);
                    break;
            }
        }







    }

    /**
     * 显示中间的内容
     * @param lineNormal
     * @param arrowsImage
     * @param visible
     * @param logistics_arrows_gray
     */
    private void setCenterShowContent(View lineNormal, ImageView arrowsImage, int visible, int logistics_arrows_gray) {
        arrowsImage.setVisibility(visible);
        lineNormal.setVisibility(View.GONE);
        arrowsImage.setImageResource(logistics_arrows_gray);
    }

    /**
     * 显示最后的内容
     * @param lineNormal
     * @param arrowsImage
     * @param resId
     */
    private void setEndShowContent(View lineNormal, ImageView arrowsImage,@DrawableRes int resId) {
        setCenterShowContent(lineNormal, arrowsImage, View.GONE, resId);
    }

}
